<?php

/**
 * 店铺的销量统计
 */
class Seller_stat_saleApp extends StoreadminbaseApp {

    var $_store_id;
    var $_order_goods_mod;

    /* 构造函数 */

    function __construct() {
        $this->Seller_stat_saleApp();
    }

    function Seller_stat_saleApp() {
        parent::__construct();
        $this->_store_id = intval($this->visitor->get('manage_store'));
        $this->_order_goods_mod = & m('ordergoods');
        $this->import_resource(
                array(
                    'script' => 'highcharts/highcharts.js,statistics.js,jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
                    'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css')
        );
    }

    /**
     * 销售统计（店铺总销量）
     *
     * @param 
     * @return 
     */
    public function index() {
        if ($_GET['type'] == 'month') {
            $year = date('Y', gmtime());
            $month = date('m', gmtime());
            $day31 = array('01', '03', '05', '07', '08', '10', '12');
            if (in_array($month, $day31)) {
                $daynum = 31;
            } else {
                if ($month == '02') {
                    //二月判断是否是闰月
                    if ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) {
                        $daynum = 29;
                    } else {
                        $daynum = 28;
                    }
                } else {
                    $daynum = 30;
                }
            }
            $main_title = intval($month) . LANG::get('month_sale_title');
            $sub_title = $year . '.' . $month . '.01-' . $year . '.' . $month . '.' . $daynum;
            $result_date_str = '';
            $request_date_str = '';
            for ($i = 1; $i <= $daynum; $i++) {
                $result_date_str .= $i . ',';
                $request_date_str .= $i < 10 ? $year . $month . '0' . $i . ',' : $year . $month . $i . ',';
            }
            $result_date_str = trim($result_date_str, ',');
            $request_date_str = trim($request_date_str, ',');


            $conditions = "seller_id = {$this->_store_id} AND month(FROM_UNIXTIME(add_time))=month(now()) ";
            $flow_array = $this->_order_goods_mod->find(array(
                'fields' => "sum(quantity) as sum,FROM_UNIXTIME(add_time, '%Y%m%d') as date ",
                'conditions' => $conditions . " group by date",
                'order' => 'add_time desc',
                'join' => 'belongs_to_order',
            ));

//            $model = Model();
//            $flow_array = $model->table('salenum')->field('date,sum(salenum) as sum')->where(array('date' => array('in', $request_date_str), 'store_id' => $_SESSION['store_id']))->group('date')->select();
            //整理流量信息数组
            $result_clicknum_str = '';
            $request_date_array = explode(',', $request_date_str);
            if (empty($flow_array)) {
                for ($i = 1; $i <= $daynum; $i++) {
                    $result_clicknum_str .= '0,';
                }
                $result_clicknum_str = trim($result_clicknum_str, ',');
            } else {
                foreach ($request_date_array as $val) {
                    $find = false;
                    foreach ($flow_array as $fk => $fv) {
                        if ($fv['date'] == $val) {
                            $result_clicknum_str .= $fv['sum'] . ',';
                            $find = true;
                            break;
                        }
                    }
                    if (!$find) {
                        $result_clicknum_str .= '0,';
                    }
                }
                $result_clicknum_str = trim($result_clicknum_str, ',');
            }

            $this->assign('usextip', 'yes');
            $this->assign('xtip', LANG::get('stat_day'));
        } elseif ($_GET['type'] == 'year') {
            $year = date('Y', gmtime());
            $main_title = $year . LANG::get('year_sale_title');
            $sub_title = $year . '.01-' . $year . '.12';
            $request_date_str = '';
            $day31 = array('01', '03', '05', '07', '08', '10', '12');
            for ($i = 1; $i <= 12; $i++) {
                $month = $i < 10 ? '0' . $i : $i;
                if (in_array($month, $day31)) {
                    for ($j = 1; $j <= 31; $j++) {
                        $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                    }
                } else {
                    if ($month == '02') {
                        //二月判断是否是闰月
                        if ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) {
                            for ($j = 1; $j <= 29; $j++) {
                                $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                            }
                        } else {
                            for ($j = 1; $j <= 28; $j++) {
                                $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                            }
                        }
                    } else {
                        for ($j = 1; $j <= 30; $j++) {
                            $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                        }
                    }
                }
            }
            $request_date_str = trim($request_date_str, ',');
            $result_date_str = '1,2,3,4,5,6,7,8,9,10,11,12';


            $conditions = "seller_id = {$this->_store_id} AND year(FROM_UNIXTIME(add_time))=year(now()) ";
            $flow_array = $this->_order_goods_mod->find(array(
                'fields' => "sum(quantity) as sum,FROM_UNIXTIME(add_time, '%Y%m%d') as date ",
                'conditions' => $conditions . " group by date",
                'order' => 'add_time desc',
                'join' => 'belongs_to_order',
            ));

//            $model = Model();
//            $flow_array = $model->table('salenum')->field('date,sum(salenum) as sum')->where(array('date' => array('in', $request_date_str), 'store_id' => $_SESSION['store_id']))->group('date')->select();
            //整理流量信息数组
            $result = array('jan' => 0, 'feb' => 0, 'mar' => 0, 'apr' => 0, 'may' => 0, 'jun' => 0, 'jul' => 0, 'aug' => 0, 'sep' => 0, 'oct' => 0, 'nov' => 0, 'dec' => 0);
            $result_clicknum_str = '';
            if (!empty($flow_array)) {
                foreach ($flow_array as $k => $v) {
                    $ym = substr(strval($v['date']), 4, 2);
                    switch ($ym) {
                        case '01':
                            $result['jan'] += $v['sum'];
                            break;
                        case '02':
                            $result['feb'] += $v['sum'];
                            break;
                        case '03':
                            $result['mar'] += $v['sum'];
                            break;
                        case '04':
                            $result['apr'] += $v['sum'];
                            break;
                        case '05':
                            $result['may'] += $v['sum'];
                            break;
                        case '06':
                            $result['jun'] += $v['sum'];
                            break;
                        case '07':
                            $result['jul'] += $v['sum'];
                            break;
                        case '08':
                            $result['aug'] += $v['sum'];
                            break;
                        case '09':
                            $result['sep'] += $v['sum'];
                            break;
                        case '10':
                            $result['oct'] += $v['sum'];
                            break;
                        case '11':
                            $result['nov'] += $v['sum'];
                            break;
                        case '12':
                            $result['dec'] += $v['sum'];
                            break;
                    }
                }
            }
            foreach ($result as $val) {
                $result_clicknum_str .= $val . ',';
            }
            $result_clicknum_str = trim($result_clicknum_str, ',');
            $this->assign('usextip', 'yes');
            $this->assign('xtip', LANG::get('stat_month'));
        } else {
            if ($_GET['add_time_from'] != '' && $_GET['add_time_to'] != '') {
                $request_date_str = '';
                $fromsp = strtotime($_GET['add_time_from']);
                $tosp = strtotime($_GET['add_time_to']);
                while ($fromsp <= $tosp) {
                    $request_date_str .= date('Ymd', $fromsp) . ',';
                    $fromsp += 86400;
                }
                $request_date_str = trim($request_date_str, ',');
                
                $conditions = "seller_id = {$this->_store_id} AND add_time > ".strtotime($_GET['add_time_from'])." AND add_time < ".strtotime($_GET['add_time_to']);
                $flow_array = $this->_order_goods_mod->find(array(
                    'fields' => "sum(quantity) as sum,FROM_UNIXTIME(add_time, '%Y%m%d') as date ",
                    'conditions' => $conditions . " group by date",
                    'order' => 'add_time desc',
                    'join' => 'belongs_to_order',
                ));

//                $model = Model();
//                $flow_array = $model->table('salenum')->field('date,sum(salenum) as sum')->where(array('date' => array('in', $request_date_str), 'store_id' => $_SESSION['store_id']))->group('date')->select();
                //整理数组信息
                $result_clicknum_str = '';
                $request_date_array = explode(',', $request_date_str);
                $daynum = count($request_date_array);
                if (empty($flow_array)) {
                    for ($i = 1; $i <= $daynum; $i++) {
                        $result_clicknum_str .= '0,';
                    }
                    $result_clicknum_str = trim($result_clicknum_str, ',');
                } else {
                    foreach ($request_date_array as $val) {
                        $find = false;
                        foreach ($flow_array as $fk => $fv) {
                            if ($fv['date'] == $val) {
                                $result_clicknum_str .= $fv['sum'] . ',';
                                $find = true;
                                break;
                            }
                        }
                        if (!$find) {
                            $result_clicknum_str .= '0,';
                        }
                    }
                    $result_clicknum_str = trim($result_clicknum_str, ',');
                }
                $result_date_str = $request_date_str;

                $from = $_GET['add_time_from'];
                $to = $_GET['add_time_to'];
                $main_title = LANG::get('store_sale_search_result');
                $sub_title = substr($from, 0, 4) . '.' . substr($from, 4, 2) . '.' . substr($from, 6, 2) . '-' . substr($to, 0, 4) . '.' . substr($to, 4, 2) . '.' . substr($to, 6, 2);

                if ($daynum > 7) {
                    $this->assign('labellean', 'yes');
                }
            } else {
                //默认显示本周店铺总销量数据
                $day = date('l', gmtime());
                switch ($day) {
                    case 'Monday':
                        $request_date_str = date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400) . ',' . date('Ymd', gmtime() + 86400 * 2) . ',' . date('Ymd', gmtime() + 86400 * 3) . ',' . date('Ymd', gmtime() + 86400 * 4) . ',' . date('Ymd', gmtime() + 86400 * 5) . ',' . date('Ymd', gmtime() + 86400 * 6);
                        $sub_title = date('Y.m.d', gmtime()) . '-' . date('Y.m.d', gmtime() + 86400 * 6);
                        break;
                    case 'Tuesday':
                        $request_date_str = date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400) . ',' . date('Ymd', gmtime() + 86400 * 2) . ',' . date('Ymd', gmtime() + 86400 * 3) . ',' . date('Ymd', gmtime() + 86400 * 4) . ',' . date('Ymd', gmtime() + 86400 * 5);
                        $sub_title = date('Y.m.d', gmtime() - 86400) . '-' . date('Y.m.d', gmtime() + 86400 * 5);
                        break;
                    case 'Wednesday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400) . ',' . date('Ymd', gmtime() + 86400 * 2) . ',' . date('Ymd', gmtime() + 86400 * 3) . ',' . date('Ymd', gmtime() + 86400 * 4);
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 2) . '-' . date('Y.m.d', gmtime() + 86400 * 4);
                        break;
                    case 'Thursday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400) . ',' . date('Ymd', gmtime() + 86400 * 2) . ',' . date('Ymd', gmtime() + 86400 * 3);
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 3) . '-' . date('Y.m.d', gmtime() + 86400 * 3);
                        break;
                    case 'Friday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400) . ',' . date('Ymd', gmtime() + 86400 * 2);
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 4) . '-' . date('Y.m.d', gmtime() + 86400 * 2);
                        break;
                    case 'Saturday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime()) . ',' . date('Ymd', gmtime() + 86400);
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 5) . '-' . date('Y.m.d', gmtime() + 86400);
                        break;
                    case 'Sunday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 6) . ',' . date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $result_date_str = date('Ymd', gmtime() - 86400 * 6) . ',' . date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 6) . '-' . date('Y.m.d', gmtime());
                        break;
                }
                $main_title = LANG::get('week_sale_title');


                $conditions = "seller_id = {$this->_store_id} AND week(FROM_UNIXTIME(add_time))=week(now()) ";
                $flow_array = $this->_order_goods_mod->find(array(
                    'fields' => "sum(quantity) as sum,FROM_UNIXTIME(add_time, '%Y%m%d') as date ",
                    'conditions' => $conditions . " group by date",
                    'order' => 'add_time desc',
                    'join' => 'belongs_to_order',
                ));

//                $model = Model();
//                $flow_array = $model->table('salenum')->field('date,sum(salenum) as sum')->where(array('date' => array('in', $request_date_str), 'store_id' => $_SESSION['store_id']))->group('date')->select();



                //整理流量信息数组
                $result_clicknum_str = '';
                $result_date_array = explode(',', $result_date_str);
                if (empty($flow_array)) {
                    $result_clicknum_str = '0,0,0,0,0,0,0';
                } else {
                    foreach ($result_date_array as $val) {
                        $find = false;
                        foreach ($flow_array as $fk => $fv) {
                            if ($fv['date'] == $val) {
                                $result_clicknum_str .= $fv['sum'] . ',';
                                $find = true;
                                break;
                            }
                        }
                        if (!$find) {
                            $result_clicknum_str .= '0,';
                        }
                    }
                    $result_clicknum_str = trim($result_clicknum_str, ',');
                }
            }
        }
        //模版输出
        $this->assign('result_date_str', $result_date_str);
        $this->assign('result_clicknum_str', $result_clicknum_str);
        $this->assign('main_title', $main_title);
        $this->assign('sub_title', $sub_title);

        /* 当前用户中心菜单 */
        $this->_curitem('seller_stat_sale');
        /* 当前所处子菜单 */
        $this->_curmenu('seller_stat_sale_index');
        $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('seller_stat_sale'), 'index.php?app=seller_stat_sale', LANG::get('seller_stat_sale_index'));
        $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('seller_stat_sale_index'));
        $this->display('seller_stat_sale.index.html');
    }

    /**
     * 商品销量排名
     *
     * @param 
     * @return 
     */
    public function goods() {
        if ($_GET['type'] == 'month') {
            $year = date('Y', gmtime());
            $month = date('m', gmtime());
            $day31 = array('01', '03', '05', '07', '08', '10', '12');
            if (in_array($month, $day31)) {
                $daynum = 31;
            } else {
                if ($month == '02') {
                    //二月判断是否是闰月
                    if ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) {
                        $daynum = 29;
                    } else {
                        $daynum = 28;
                    }
                } else {
                    $daynum = 30;
                }
            }
            $main_title = intval($month) . LANG::get('month_sale_rank_title');
            $sub_title = $year . '.' . $month . '.01-' . $year . '.' . $month . '.' . $daynum;
            $request_date_str = '';
            for ($i = 1; $i <= $daynum; $i++) {
                $result_date_str .= $i . ',';
                $request_date_str .= $i < 10 ? $year . $month . '0' . $i . ',' : $year . $month . $i . ',';
            }
            $request_date_str = trim($request_date_str, ',');
            $conditions = "seller_id = {$this->_store_id} AND month(FROM_UNIXTIME(add_time))=month(now()) ";
        } elseif ($_GET['type'] == 'year') {
            $year = date('Y', gmtime());
            $main_title = $year . LANG::get('year_sale_rank_title');
            $sub_title = $year . '.01-' . $year . '.12';
            $request_date_str = '';
            $day31 = array('01', '03', '05', '07', '08', '10', '12');
            for ($i = 1; $i <= 12; $i++) {
                $month = $i < 10 ? '0' . $i : $i;
                if (in_array($month, $day31)) {
                    for ($j = 1; $j <= 31; $j++) {
                        $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                    }
                } else {
                    if ($month == '02') {
                        //二月判断是否是闰月
                        if ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) {
                            for ($j = 1; $j <= 29; $j++) {
                                $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                            }
                        } else {
                            for ($j = 1; $j <= 28; $j++) {
                                $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                            }
                        }
                    } else {
                        for ($j = 1; $j <= 30; $j++) {
                            $request_date_str .= $j < 10 ? $year . $month . '0' . $j . ',' : $year . $month . $j . ',';
                        }
                    }
                }
            }
            $request_date_str = trim($request_date_str, ',');
            $conditions = "seller_id = {$this->_store_id} AND year(FROM_UNIXTIME(add_time))=year(now()) ";
        } else {
            if ($_GET['add_time_from'] != '' && $_GET['add_time_to'] != '') {
                $request_date_str = '';
                $fromsp = strtotime($_GET['add_time_from']);
                $tosp = strtotime($_GET['add_time_to']);

                while ($fromsp <= $tosp) {
                    $request_date_str .= date('Ymd', $fromsp) . ',';
                    $fromsp += 86400;
                }
                $request_date_str = trim($request_date_str, ',');
                
                
                
                $from = $_GET['add_time_from'];
                $to = $_GET['add_time_to'];
                $main_title = LANG::get('store_sale_rank_search_result');
                $sub_title = substr($from, 0, 4) . '.' . substr($from, 4, 2) . '.' . substr($from, 6, 2) . '-' . substr($to, 0, 4) . '.' . substr($to, 4, 2) . '.' . substr($to, 6, 2);
                
                
                $conditions = "seller_id = {$this->_store_id} AND add_time > ".strtotime($_GET['add_time_from'])." AND add_time < ".strtotime($_GET['add_time_to']);

            } else {
                //默认显示本周商品流量排名
                $day = date('l', gmtime());
                switch ($day) {
                    case 'Monday':
                        $request_date_str = date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime()) . '-' . date('Y.m.d', gmtime() + 86400 * 6);
                        break;
                    case 'Tuesday':
                        $request_date_str = date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400) . '-' . date('Y.m.d', gmtime() + 86400 * 5);
                        break;
                    case 'Wednesday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 2) . '-' . date('Y.m.d', gmtime() + 86400 * 4);
                        break;
                    case 'Thursday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 3) . '-' . date('Y.m.d', gmtime() + 86400 * 3);
                        break;
                    case 'Friday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 4) . '-' . date('Y.m.d', gmtime() + 86400 * 2);
                        break;
                    case 'Saturday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 5) . '-' . date('Y.m.d', gmtime() + 86400);
                        break;
                    case 'Sunday':
                        $request_date_str = date('Ymd', gmtime() - 86400 * 6) . ',' . date('Ymd', gmtime() - 86400 * 5) . ',' . date('Ymd', gmtime() - 86400 * 4) . ',' . date('Ymd', gmtime() - 86400 * 3) . ',' . date('Ymd', gmtime() - 86400 * 2) . ',' . date('Ymd', gmtime() - 86400) . ',' . date('Ymd', gmtime());
                        $sub_title = date('Y.m.d', gmtime() - 86400 * 6) . '-' . date('Y.m.d', gmtime());
                        break;
                }
                $main_title = LANG::get('week_sale_rank_title');
                
                $conditions = "seller_id = {$this->_store_id} AND week(FROM_UNIXTIME(add_time))=week(now()) ";
            }
        }
        
        
        
        
        
        $flow_array = $this->_order_goods_mod->find(array(
            'fields' => "sum(quantity) as sum,goods_id,goods_name,FROM_UNIXTIME(add_time, '%Y%m%d') as date ",
            'conditions' => $conditions . " group by goods_id",
            'order' => 'sum desc',
            'join' => 'belongs_to_order',
            'limit' => '10',
        ));
        
        
        
        //处理数组信息
        $result_goods_str = '';
        $result_clicknum_str = '';
        if (!empty($flow_array)) {
            foreach ($flow_array as $k => $v) {
                $result_goods_str .= "'" . addslashes(html_entity_decode($v['goods_name'])) . "',"; //还原被转换的双引号，加斜线防止中间有单引号使页面的JS数组出错
                $result_clicknum_str .= $v['sum'] . ',';
            }
        }
        $result_goods_str = trim($result_goods_str, ',');
        $result_clicknum_str = trim($result_clicknum_str, ',');
        //模版输出
        $this->assign('result_goods_str', $result_goods_str);
        $this->assign('result_clicknum_str', $result_clicknum_str);
        $this->assign('main_title', $main_title);
        $this->assign('sub_title', $sub_title);
        
        /* 当前用户中心菜单 */
        $this->_curitem('seller_stat_sale');
        /* 当前所处子菜单 */
        $this->_curmenu('seller_stat_sale_goods');
        $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('seller_stat_sale'), 'index.php?app=seller_stat_sale&act=goods', LANG::get('seller_stat_sale_goods'));
        $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('seller_stat_sale_goods'));
        $this->display('seller_stat_sale.goods.html');
    }

    function _get_member_submenu() {
        $menus = array(
            array(
                'name' => 'seller_stat_sale_index',
                'url' => 'index.php?app=seller_stat_sale',
            ),
            array(
                'name' => 'seller_stat_sale_goods',
                'url' => 'index.php?app=seller_stat_sale&act=goods',
            )
        );
        return $menus;
    }

}

?>
